
/**加载添加计划页面*/
function loadAddSalePlan(btn) {
    var type = $(btn).attr("data-click");
    $("#saleplanTypehide").val(type);
    $.post(ctx+"SaleHelp/loadAddSalePlan",{},function (r) {
        $("#sale_help_one").empty().append(r).modal('show').draggable();
    });
}

/**新建个人分组**/
function addPersonModalGroup() {
    $.post(ctx+"SaleHelp/loadperSonGroup",{},function (r) {
        $("#sale_help_one").empty().append(r).modal('show');
    });
}
/**保存个人分组**/
function savePersonGroup() {
    var groupName = $("#personGroupName").val();
    if (groupName == ""){$JuXue.n_danger("请填写分组名称");return;}
    var length = groupName.length;
    if (length > 8 ){$JuXue.n_danger("输入的名称过长");return;}
    $.post(ctx+"SaleHelp/addModalGroup",{cSaleMtype:1,cSaleGroup:0,cSaleTitle:groupName},function (r) {
        if (r.code == 0){
            $("#sale_help_one").modal("hide");
            init_modal("acage","");
        }else{
            $JuXue.n_danger("新建分组失败");
        }
    });
}

/**添加个人模板**/
function addPersonModal() {
    $.post(ctx+"SaleHelp/loadPersonModal",{},function (r) {
        $("#sale_help_one").empty().append(r).modal('show');
    });
}

/**选择个人模板分组**/
function selectPersonGroup(btn) {
    $("#acage").find("h3").each(function () {
       $(this).removeClass("bg-gr-lighter");
    });
    $("#acage").find("li").each(function () {
        $(this).removeClass("bg-gr-lighter");
    });
    $("#upDownData").val("1");
    $(btn).parent().parent().addClass("bg-gr-lighter");
    var uuid = $(btn).parent().parent().parent().attr("uuid");
    $("#deleteModalUuid").val(uuid);
    $("#personModal").empty().append("<ul class=\"timeline height-500 overflow-auto\" id=\"modalListByGroup\"> </ul>");
    $.getJSON(ctx+"SaleHelp/selectAllModalByUuid",{cSaleUuid:uuid},function (r) {
        if (r.code == 0){
            var data = r.msg;
            $("#modalListByGroup").empty();
            $.each(data,function (index,val) {
                var allli = "<li>\n" +
                "   <div class=\"timeline-time width-100\">\n" +
                "    <span class=\"date m-l-15\">"+val.oneParame+"</span>\n" +
                "    <span class=\"time f-s-15\">"+val.twoParame+"</span>\n" +
                "   </div>\n" +
                "   <div class=\"timeline-body width-500 p-10 \">\n" +
                "     <div class=\"timeline-header\">\n" +
                "       <span class=\"username\">"+val.cSaleTitle+"</span>\n" +
                "       <span class=\"pull-right text-muted p-r-10\">"+val.cSaleCtime+"</span>\n" +
                "     </div>\n" +
                "   <div class=\"timeline-content \">\n" +
                "        <p class=\"lead f-s-16\">\n" +
                "          <i class=\"fa fa-comment text-info fa-fw pull-left \"></i>: " +val.cSaleDesc+
                "        </p>\n" +
                "   </div>\n" +
                "  </div>\n" +
                " </li>";
                $("#modalListByGroup").append(allli);
            });
        }else{
            $JuXue.n_danger("获取模板列表失败");
        }
    });
}

/**选择个人模板**/
function selectPersonModal(btn) {
    $("#acage").find("h3").each(function () {
        $(this).removeClass("bg-gr-lighter");
    });
    $("#acage").find("li").each(function () {
        $(this).removeClass("bg-gr-lighter");
    });
    $("#upDownData").val("0");
    $(btn).parent().addClass("bg-gr-lighter");
    var uuid = $(btn).parent().attr("uuid");
     $("#deleteModalUuid").val(uuid);
    var title = $(btn).text();
     /**加载模板的详情**/
    $.post(ctx+"SaleHelp/personModalDetail",function (r) {
        $("#personModal").empty().append(r);
        $("#cSaleTitle").val(title);
    });
}
/**下移**/
function personModalDown() {
    var ble = false;
    $("#acage").find("h3").each(function () {
         var ble1= $(this).hasClass("bg-gr-lighter");if (ble1) ble = ble1;
    });
    $("#acage").find("li").each(function () {
        var ble2 = $(this).hasClass("bg-gr-lighter");if (ble2) ble = ble2;
    });
    if (!ble) {$JuXue.n_danger("请选择移动的模板");return}

    var data = $("#upDownData").val();
    if (data == "0"){
        //模板下移
        $("#acage").find("li").each(function () {
            var lis = $(this).hasClass("bg-gr-lighter");
            if (lis){
                var li = $(this).next();
                if (li.length <= 0){$JuXue.n_danger("已经最后一个,不能下移");return}
                var beforeid = li.attr("uuid");
                var afertod = $(this).attr("uuid");
                $.post(ctx+"SaleHelp/upDownOption",{beforUuid:beforeid,afterUuid:afertod},function (r) {
                    if (r.code == 0){
                        $JuXue.n_success("下移成功");
                        init_modal("acage","");
                    }else{
                        $JuXue.n_danger("下移失败");
                    }
                });
            }
        });
    }else{
        //分组下移
        $("#acage").find("h3").each(function () {
            var lis = $(this).hasClass("bg-gr-lighter");
            if (lis){
                var div = $(this).parent().next();
                if (div.length <= 0){$JuXue.n_danger("已经最后一个,不能下移");return}
                var beforeid = div.attr("uuid");
                var afertod = $(this).parent().attr("uuid");
                $.post(ctx+"SaleHelp/upDownOption",{beforUuid:beforeid,afterUuid:afertod},function (r) {
                    if (r.code == 0){
                        $JuXue.n_success("下移成功");
                        init_modal("acage","");
                    }else{
                        $JuXue.n_danger("下移失败");
                    }
                });
            }
        });
    }
}

/**上移动**/
function personModalUp() {
    var ble = false;
    $("#acage").find("h3").each(function () {
        var ble1= $(this).hasClass("bg-gr-lighter");if (ble1) ble = ble1;
    });
    $("#acage").find("li").each(function () {
        var ble2 = $(this).hasClass("bg-gr-lighter");if (ble2) ble = ble2;
    });
    if (!ble) {$JuXue.n_danger("请选择移动的模板");return}

    var data = $("#upDownData").val();
    if (data == "0"){
        //模板上移
        $("#acage").find("li").each(function () {
            var lis = $(this).hasClass("bg-gr-lighter");
            if (lis){
                var li = $(this).prev();
                if (li.length <= 0){$JuXue.n_danger("已经第一个,不能上移");return}
                var beforeid = li.attr("uuid");
                var afertod = $(this).attr("uuid");
                $.post(ctx+"SaleHelp/upDownOption",{beforUuid:beforeid,afterUuid:afertod},function (r) {
                    if (r.code == 0){
                        $JuXue.n_success("上移成功");
                        init_modal("acage","");
                    }else{
                        $JuXue.n_danger("上移失败");
                    }
                });
            }
        });
    }else{
        //分组下移
        $("#acage").find("h3").each(function () {
            var lis = $(this).hasClass("bg-gr-lighter");
            if (lis){
                var div = $(this).parent().prev();
                if (div.length <= 0){$JuXue.n_danger("已经第一个,不能上移");return}
                var beforeid = div.attr("uuid");
                var afertod = $(this).parent().attr("uuid");
                $.post(ctx+"SaleHelp/upDownOption",{beforUuid:beforeid,afterUuid:afertod},function (r) {
                    if (r.code == 0){
                        $JuXue.n_success("上移成功");
                        init_modal("acage","");
                    }else{
                        $JuXue.n_danger("上移失败");
                    }
                });
            }
        });
    }
}
/**删除个人模板**/
function personModalDelete() {
    var ble = false;
    $("#acage").find("h3").each(function () {
        var ble1= $(this).hasClass("bg-gr-lighter");if (ble1) ble = ble1;
    });
    $("#acage").find("li").each(function () {
        var ble2 = $(this).hasClass("bg-gr-lighter");if (ble2) ble = ble2;
    });
    if (!ble) {$JuXue.n_danger("请选择移动的模板");return}

    var uuid = $("#deleteModalUuid").val();
    if (uuid != ""){
        $JuXue.confirm({
            text: "确定删除模板？",
            confirmButtonText: "确定删除"
        }, function() {
            $.post(ctx+"SaleHelp/updateModalInfo",{cSaleUuid:uuid,cSaleDelete:"0"},function (r) {
                if (r.code == 0){
                    $JuXue.n_success("删除成功");
                    init_modal("acage","");
                }else{
                    $JuXue.n_danger("删除失败");
                }
            });
        });

    }
}
/**修改分组的名称**/
function updatePersonGroup(btn) {
    var uuid = $(btn).parent().parent().parent().attr("uuid");
    var title = $(btn).prev().text();
    $.post(ctx+"SaleHelp/editPersonModal",function (r) {
        $("#sale_help_one").empty().append(r).modal('show');
        $("#saveEdit").val(uuid);$("#newGroupName").val(title);
    })
}
/**保存分组名称**/
function saveNewGroupName() {
   var uuid = $("#saveEdit").val();
   var title  = $("#newGroupName").val();
    $.post(ctx+"SaleHelp/updateModalInfo",{cSaleUuid:uuid,cSaleTitle:title},function (r) {
        if (r.code == 0){
            $JuXue.n_success("修改成功");
            init_modal("acage","");
            $("#sale_help_one").empty().modal('hide');
        }else{
            $JuXue.n_danger("修改失败");
        }
    });
}




